import 'package:flutter/cupertino.dart';
import 'package:flutter_app_05/action/states/sp_util.dart';
import 'package:shared_preferences/shared_preferences.dart';

class DartState with ChangeNotifier {
  /// 夜间模式 1: 关闭 2: 开启
  static int _darkMode = 1;

  int get darkMode => _darkMode;

  void changeMode(int darkMode) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setInt("dark", darkMode);
    _darkMode = _darkMode = prefs.getInt("dark") ?? 0;
    notifyListeners();
    SpUtil.putInt(SpConstant.DARK_MODE, darkMode);
  }

  Future initMode() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    _darkMode = prefs.getInt("dark") ?? 1;
    setDark(prefs.getInt("dark") ?? 1);
  }

  void setDark(int status) {
    _darkMode = status;
  }

  int getdart() {
    return _darkMode;
  }
}